import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import static section_02.SwingConsole.run;

/**
 * @Author ZhangGJ
 * @Date 2019/10/07
 */
class AllAction extends JFrame {
    // The JMenuItem's derivatives JCheckBoxMenuItem, JMenu &
    // JRadioButtonMenuItem will not be shown separately:
    JMenuItem mi = new JMenuItem("Menu Item");
    JTextField txt = new JTextField(30);
    JButton b1 = new JButton("Button 1");
    JComboBox jcb = new JComboBox(new String[] {"Elements", "To", "Place", "In", "Combobox"});
    JFileChooser jfc = new JFileChooser(".");

    public AllAction() {
        setLayout(new FlowLayout());
        add(mi);
        add(txt);
        add(b1);
        add(jcb);
        add(jfc);
        b1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                txt.setText("Button pressed");
            }
        });
        txt.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane
                    .showMessageDialog(null, "JTexfField ActionListener fired", "information",
                        JOptionPane.INFORMATION_MESSAGE);
            }
        });
        jcb.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                txt.setText("JComboBox selected: " + jcb.getSelectedItem());
            }
        });
        jfc.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                txt.setText("FileChooser ActionListener fired: " + jfc.getSelectedFile());
            }
        });
        mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                txt.setText("JMenuItem selected");
            }
        });
        new Timer(5000, new ActionListener() {
            int i = 0;

            public void actionPerformed(ActionEvent e) {
                txt.setText("Timer Ticked " + i++);
            }
        }).start();
    }
}


public class E07_AllAction {
    public static void main(String args[]) {
        run(new AllAction(), 550, 400);
    }
}
